/*
 * mainGUI.java
 *
 * Created on August 22, 2007, 9:36 PM
 */
package mainBoard;

import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileNameExtensionFilter;
import remote.ServerBoardInterface;
import remote.WhiteBoardInterface;
import whiteBoard.shapeInfo;


/* this is main jFrame that is displayed at the start */
public class mainGUI extends javax.swing.JFrame {

    Registry registry;
    /* initially disable the stroke*/
    private boolean strokeEnabled = false;
    /* if connected the server of this whiteboardapp*/
    private ServerBoardInterface server;
    /* initial strokeWidth*/
    private float strokeWidth = 1.0f;
    /* shape type like Circle, Rectangle, FilledCircle, Line etc.*/
    private String shapeType;
    
    /* color of the shape type defined
     * default color before choosing from color chooser is black
     */
    public Color color=Color.BLACK;
    
    int x, y;
    int mousePressedx, mousePressedy;
    boolean exportFirstTime = true;
    /* at first not connected to the server*/
    boolean connToServer = false;
    private int flag = -1;
    // String openFile,saveFile;
    
    /* instance of connect form that will be displayed when connect is clicked*/
    ConnectForm connectForm;
    /* fileChooser is an instance of JFileChooser*/
    private JFileChooser fileChooser;

    /* Creates new form mainGUI */
    public mainGUI() {
        initComponents();
        String path = "c:";
        fileChooser = new JFileChooser(path);
        /* sends this mainGUI as an instance for the paintarea
         * i.e this is the connection point between mainGUI and paintArea*/
        try {
            paintArea1.setWhiteAppInstance(this);

        } catch (Exception exception) {
            System.out.println("Sorry ,there is an error");
        }

    }

    /**
     * connects to the server
     * this method is called from inside the connectFrom.java after filling the necessary information
     * @param server_addr server address
     * @param port server port
     * @param userName user name of the client using this whiteboard
     */
    void ConnectServer(String server_addr, int port_no, String userName) {
        try {
            registry = LocateRegistry.getRegistry(server_addr, (new Integer(port_no)).intValue());
            /* look up the remote object*/
            this.server = (ServerBoardInterface) (registry.lookup("Boardserver"));
            /*export the paintarea class as a remote object so that the server will be able to call it's functions on desire
            * port no is specified as 0 because to allow server to connect with anonymous port*/
            UnicastRemoteObject.exportObject((WhiteBoardInterface) (this.paintArea1), 0);
            // call the remote method*/
            if (this.paintArea1.shapeList.isEmpty()) {
            } else {
                server.setGlobalShapeList(this.paintArea1.shapeList);
            }
            int disp = server.Regist((WhiteBoardInterface) (this.paintArea1), userName);
            if (disp == 500) {
                setStatus(userName + " is already connected");
            } else if (disp == -999) {
                setStatus("Client with name " + userName + " already connected");
            } else {
                setStatus("connected: " + userName);
                connect.setEnabled(false);
                connToServer = true;
            }
            /*connection point between the server and the client*/
            this.paintArea1.setServer(this.server); 
            System.out.println("server said u r connected " + disp);
        } catch (RemoteException ex) {
            Logger.getLogger(mainGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
    /* call the remote method*/
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        statusANDmousexy = new javax.swing.JPanel();
        status = new javax.swing.JLabel();
        mousexy = new javax.swing.JLabel();
        selected = new javax.swing.JLabel();
        selectedcolor = new javax.swing.JButton();
        toolBar = new javax.swing.JPanel();
        buttonBar = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        circle = new javax.swing.JButton();
        eraser = new javax.swing.JButton();
        line = new javax.swing.JButton();
        rectangle = new javax.swing.JButton();
        filledrectangle = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        strokesmall = new javax.swing.JButton();
        strokelarge = new javax.swing.JButton();
        strokelarger = new javax.swing.JButton();
        strokelargest = new javax.swing.JButton();
        colorpallette = new javax.swing.JButton();
        text = new javax.swing.JButton();
        connectDisconnect = new javax.swing.JPanel();
        drawingArea = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        paintArea1 = new whiteBoard.paintArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        File = new javax.swing.JMenu();
        jnew = new javax.swing.JMenuItem();
        jText = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jExit = new javax.swing.JMenuItem();
        edit = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        network = new javax.swing.JMenu();
        connect = new javax.swing.JMenuItem();
        newsuperpeer = new javax.swing.JMenuItem();
        newnode = new javax.swing.JMenuItem();
        help = new javax.swing.JMenu();
        jHelp = new javax.swing.JMenuItem();
        jAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("White Board");
        setBackground(new java.awt.Color(124, 154, 138));
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setName("prabesh"); // NOI18N
        setResizable(false);

        statusANDmousexy.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        status.setText("Status :      Not Connected");
        status.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Status", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.BELOW_BOTTOM));

        mousexy.setText("X:     ");
        mousexy.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mouse Position", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.BELOW_BOTTOM));

        selected.setText("selected: NONE");

        selectedcolor.setBackground(new java.awt.Color(0, 0, 0));
        selectedcolor.setToolTipText("selected color");
        selectedcolor.setEnabled(false);

        javax.swing.GroupLayout statusANDmousexyLayout = new javax.swing.GroupLayout(statusANDmousexy);
        statusANDmousexy.setLayout(statusANDmousexyLayout);
        statusANDmousexyLayout.setHorizontalGroup(
            statusANDmousexyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusANDmousexyLayout.createSequentialGroup()
                .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mousexy, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statusANDmousexyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(selectedcolor, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                    .addComponent(selected, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE))
                .addContainerGap())
        );
        statusANDmousexyLayout.setVerticalGroup(
            statusANDmousexyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusANDmousexyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(status, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                .addComponent(mousexy, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusANDmousexyLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(selectedcolor, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addComponent(selected, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        toolBar.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "TOOLBAR", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));
        toolBar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                toolBarMouseClicked(evt);
            }
        });

        buttonBar.setBorder(javax.swing.BorderFactory.createCompoundBorder());

        jButton1.setBackground(new java.awt.Color(204, 204, 204));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/selector.gif"))); // NOI18N
        jButton1.setToolTipText("Select an object");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        circle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pen.gif"))); // NOI18N
        circle.setToolTipText("Draw Freehand");
        circle.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle.gif"))); // NOI18N
        circle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                circleMouseClicked(evt);
            }
        });
        circle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                circleActionPerformed(evt);
            }
        });

        eraser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/eraser.gif"))); // NOI18N
        eraser.setToolTipText("erase an object");
        eraser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                eraserMouseClicked(evt);
            }
        });

        line.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/line.gif"))); // NOI18N
        line.setToolTipText("Draw line");
        line.setFocusPainted(false);
        line.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lineMouseClicked(evt);
            }
        });

        rectangle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/rectangle.gif"))); // NOI18N
        rectangle.setToolTipText("Draw Rectangle");
        rectangle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                rectangleMousePressed(evt);
            }
        });

        filledrectangle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/filledRectangle.gif"))); // NOI18N
        filledrectangle.setToolTipText("Draw Filled Rectangle");
        filledrectangle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                filledrectangleMouseClicked(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/circle.gif"))); // NOI18N
        jButton7.setToolTipText("Draw Circle");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton7MouseClicked(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/filledCircle.gif"))); // NOI18N
        jButton8.setToolTipText("Draw Filled Circle");
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton8MouseClicked(evt);
            }
        });

        strokesmall.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/strokeSmall.gif"))); // NOI18N
        strokesmall.setEnabled(false);
        strokesmall.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                strokesmallMouseClicked(evt);
            }
        });

        strokelarge.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/strokeLarge.gif"))); // NOI18N
        strokelarge.setEnabled(false);
        strokelarge.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                strokelargeMouseClicked(evt);
            }
        });

        strokelarger.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/strokeLarger.gif"))); // NOI18N
        strokelarger.setEnabled(false);
        strokelarger.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                strokelargerMouseClicked(evt);
            }
        });

        strokelargest.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/strokeLargest.gif"))); // NOI18N
        strokelargest.setEnabled(false);
        strokelargest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                strokelargestActionPerformed(evt);
            }
        });

        colorpallette.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/color.gif"))); // NOI18N
        colorpallette.setToolTipText("Color Chooser");
        colorpallette.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                colorpalletteMouseClicked(evt);
            }
        });

        text.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/text.gif"))); // NOI18N
        text.setToolTipText("Type Text");
        text.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                textMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout buttonBarLayout = new javax.swing.GroupLayout(buttonBar);
        buttonBar.setLayout(buttonBarLayout);
        buttonBarLayout.setHorizontalGroup(
            buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonBarLayout.createSequentialGroup()
                .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(buttonBarLayout.createSequentialGroup()
                        .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(buttonBarLayout.createSequentialGroup()
                                .addComponent(rectangle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(filledrectangle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(buttonBarLayout.createSequentialGroup()
                                .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(buttonBarLayout.createSequentialGroup()
                                .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jButton1, 0, 0, Short.MAX_VALUE)
                                    .addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, 30, Short.MAX_VALUE))
                                .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(buttonBarLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(eraser, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonBarLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(circle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(strokelarger, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(strokelarge, 0, 50, Short.MAX_VALUE)
                                    .addComponent(strokesmall, javax.swing.GroupLayout.PREFERRED_SIZE, 50, Short.MAX_VALUE)))
                            .addComponent(strokelargest, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(colorpallette, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        buttonBarLayout.setVerticalGroup(
            buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonBarLayout.createSequentialGroup()
                .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(buttonBarLayout.createSequentialGroup()
                        .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(circle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(eraser, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rectangle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(filledrectangle, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(buttonBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(buttonBarLayout.createSequentialGroup()
                        .addComponent(strokesmall, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(strokelarge, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(strokelarger, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(strokelargest, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(colorpallette, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout connectDisconnectLayout = new javax.swing.GroupLayout(connectDisconnect);
        connectDisconnect.setLayout(connectDisconnectLayout);
        connectDisconnectLayout.setHorizontalGroup(
            connectDisconnectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 132, Short.MAX_VALUE)
        );
        connectDisconnectLayout.setVerticalGroup(
            connectDisconnectLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 174, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout toolBarLayout = new javax.swing.GroupLayout(toolBar);
        toolBar.setLayout(toolBarLayout);
        toolBarLayout.setHorizontalGroup(
            toolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(toolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(connectDisconnect, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(buttonBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        toolBarLayout.setVerticalGroup(
            toolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBarLayout.createSequentialGroup()
                .addComponent(buttonBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(connectDisconnect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane1.setAutoscrolls(true);

        paintArea1.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.darkGray, java.awt.Color.gray));
        paintArea1.setShape("<Not Set>");
        paintArea1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                paintArea1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                paintArea1MouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                paintArea1MousePressed(evt);
            }
        });
        paintArea1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                paintArea1MouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                paintArea1MouseMoved(evt);
            }
        });
        jScrollPane1.setViewportView(paintArea1);

        javax.swing.GroupLayout drawingAreaLayout = new javax.swing.GroupLayout(drawingArea);
        drawingArea.setLayout(drawingAreaLayout);
        drawingAreaLayout.setHorizontalGroup(
            drawingAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
        );
        drawingAreaLayout.setVerticalGroup(
            drawingAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
        );

        File.setText("File");
        File.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FileActionPerformed(evt);
            }
        });

        jnew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jnew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/folder_new.png"))); // NOI18N
        jnew.setText("New");
        jnew.setToolTipText("Create a new Whiteboard");
        jnew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jnewActionPerformed(evt);
            }
        });
        File.add(jnew);

        jText.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jText.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/folder_open.png"))); // NOI18N
        jText.setText("Open");
        jText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextActionPerformed(evt);
            }
        });
        File.add(jText);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif"))); // NOI18N
        jMenuItem3.setText("Save");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        File.add(jMenuItem3);

        jExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/file_exit.png"))); // NOI18N
        jExit.setText("Exit");
        jExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jExitActionPerformed(evt);
            }
        });
        File.add(jExit);

        jMenuBar1.add(File);

        edit.setText("Edit");
        edit.setToolTipText("Edit the image here");
        edit.setEnabled(false);
        edit.setFocusable(false);
        edit.setRequestFocusEnabled(false);
        edit.setRolloverEnabled(false);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/copy.gif"))); // NOI18N
        jMenuItem4.setText("Copy");
        edit.add(jMenuItem4);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cut.gif"))); // NOI18N
        jMenuItem5.setText("Cut");
        edit.add(jMenuItem5);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/paste.png"))); // NOI18N
        jMenuItem6.setText("Paste");
        edit.add(jMenuItem6);

        jMenuBar1.add(edit);

        network.setText("Network");
        network.setDoubleBuffered(true);
        network.setHideActionText(true);
        network.setOpaque(false);
        network.setVerifyInputWhenFocusTarget(false);
        network.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                networkActionPerformed(evt);
            }
        });

        connect.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
        connect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/network.png"))); // NOI18N
        connect.setText("Connect ");
        connect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectActionPerformed(evt);
            }
        });
        network.add(connect);

        newsuperpeer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        newsuperpeer.setText("New Super Peer");
        newsuperpeer.setEnabled(false);
        newsuperpeer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newsuperpeerActionPerformed(evt);
            }
        });
        network.add(newsuperpeer);

        newnode.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.ALT_MASK));
        newnode.setText("New Node");
        newnode.setEnabled(false);
        newnode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newnodeActionPerformed(evt);
            }
        });
        network.add(newnode);

        jMenuBar1.add(network);

        help.setText("Help");

        jHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        jHelp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/abiword_abi.png"))); // NOI18N
        jHelp.setText("Help");
        jHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jHelpActionPerformed(evt);
            }
        });
        help.add(jHelp);

        jAbout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
        jAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bookmark_add.png"))); // NOI18N
        jAbout.setText("About");
        jAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAboutActionPerformed(evt);
            }
        });
        help.add(jAbout);

        jMenuBar1.add(help);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(drawingArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(statusANDmousexy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(drawingArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(17, 17, 17)
                .addComponent(statusANDmousexy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void newnodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newnodeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_newnodeActionPerformed

private void newsuperpeerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newsuperpeerActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_newsuperpeerActionPerformed

private void connectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectActionPerformed
// when the user does some actin on the connect link this code is run:
    if (!connToServer) {
        connectForm = new ConnectForm(this);
        connectForm.setVisible(true);
    } else {
        connect.setEnabled(false);
    }
}//GEN-LAST:event_connectActionPerformed

private void networkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_networkActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_networkActionPerformed

private void FileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_FileActionPerformed

private void eraserMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_eraserMouseClicked
    this.paintArea1.saveCurrentInstance(); //saves the shapelist if not empty in a file
    this.paintArea1.setselector(false);
    setselector("Eraser");
    shapeType = "Eraser"; //sets the shapetype as text
    sendShapeBoard(); //sends to the current shapeinfo to the paintarea
    this.paintArea1.setDeleter(true);
}//GEN-LAST:event_eraserMouseClicked

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// run this code when the selector icon is clicked:
    this.paintArea1.setselector(true);
    setselector("Selector");
    this.paintArea1.selectorWork();


/*//GEN-LAST:event_jButton1MouseClicked
         */
    }

    public void save() {
        fileChooser.resetChoosableFileFilters();
        fileChooser.setAcceptAllFileFilterUsed(false);
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Image (*.png)", "png"));
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Image (*.gif)", "gif"));
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Image (*.jpg)", "jpg", "jpeg"));
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Board file(*.out)", "out"));
        int returnVal = fileChooser.showSaveDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            System.out.println(file.getName());
            if (file.exists()) {
                //Overwrite File ??
                int chk = JOptionPane.showConfirmDialog(this, "File : \"" + file.getName() + "\" already exists.\nDo you want to overwrite?", "file already exist", 2);
                if (chk == 0) {
                    System.out.println("overwrite file");
                    this.paintArea1.saveFile(file, fileChooser.getCurrentDirectory().toString());
                } else {
                    save();
                }
            } else {
                flag = 1;
            }
            if (flag == 1) {
                System.out.println("Saving: " + file.getAbsoluteFile() + ".");
                this.paintArea1.saveFile(file, fileChooser.getCurrentDirectory().toString());
            }
            flag = -1;
        } else {
            System.out.println("Save command cancelled by user.");
        }
    }

private void textMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_textMouseClicked
// run this code when the text icon is clicked::
    this.paintArea1.saveCurrentInstance(); //saves the shapelist if not empty in a file
    this.paintArea1.setselector(false);

    shapeType = "Text"; //sets the shapetype as text
    sendShapeBoard(); //sends to the current shapeinfo to the paintarea
    strokeEnabled = false;
    setEnableStroke(); //does not enable the stroke for this selected button
    setselector("Text"); //sets the text as the selected text in the status bar
}//GEN-LAST:event_textMouseClicked

private void paintArea1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_paintArea1MousePressed
// run this code when the mouse is pressed in the paintarea:
    mousePressedx = evt.getX(); //get the x position of the point where the mouse is presses
    mousePressedy = evt.getY(); //get the y position of the point where the mouse is presses
    mousexy.setText("x:   " + 0 + "    y:  " + 0); //sets the initial measurement
}//GEN-LAST:event_paintArea1MousePressed

private void paintArea1MouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_paintArea1MouseDragged
// this code is executed when the mouse is dragged in the paintarea to display the measurement:
    int mousex; //length in the x direction
    int mousey; //length in the y direction
    mousex = Math.abs(mousePressedx - evt.getX()); //subtract the current position from the mouse pressed position
    mousey = Math.abs(mousePressedy - evt.getY());
    mousexy.setText("x:   " + mousex + "    y:  " + mousey); //display the currently selected dimension
}//GEN-LAST:event_paintArea1MouseDragged

private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton8MouseClicked
// this code is executed when the filled circle icon is clicked:
    this.paintArea1.setselector(false);
    this.paintArea1.saveCurrentInstance(); //saves the shapelist if not empty in a file
    shapeType = "FilledCircle"; //sets the shapetype as filled circle
    sendShapeBoard();
    strokeEnabled = false; //this will set the stroke disbled
    setEnableStroke();
    setselector("Filled Circle"); //set the status bar text
}//GEN-LAST:event_jButton8MouseClicked

private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseClicked
// TODO add your handling code here:
    this.paintArea1.saveCurrentInstance(); //saves the shapelist if not empty in a file
    shapeType = "Circle"; //sets the shapetype as circle
    this.paintArea1.setselector(false);
    sendShapeBoard();
    strokeEnabled = true; //enable the stroke for this behaviour
    setEnableStroke();
    setselector("Circle"); //set the status bar text
    this.paintArea1.setselector(false);
}//GEN-LAST:event_jButton7MouseClicked

private void filledrectangleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_filledrectangleMouseClicked
// TODO add your handling code here:
    this.paintArea1.setselector(false);
    this.paintArea1.saveCurrentInstance(); //saves the shapelist if not empty in a file
    shapeType = "FilledRectangle"; //sets the shapetype as filled rectangle
    sendShapeBoard();
    strokeEnabled = false;
    setEnableStroke(); //does not enable the stroke
    setselector("Filled Rectangle"); //sets the status bar text
}//GEN-LAST:event_filledrectangleMouseClicked

private void colorpalletteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_colorpalletteMouseClicked
// when the colorChooser icon is pressed:
    JColorChooser colorChoose = new JColorChooser();
    Color chooseColor = JColorChooser.showDialog(this, "Choose a Color", Color.GREEN); //returns a choosed color
    color = chooseColor; //gets the color choosed by the user
    selectedcolor.setBackground(color);
    sendShapeBoard(); //sends the whiteboard info with new color
}//GEN-LAST:event_colorpalletteMouseClicked

private void strokelargerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_strokelargerMouseClicked
// When the StrokeWidth icon is pressed:
    this.strokeWidth = 3.0f;
    sendShapeBoard(); //sends the whiteboard info with new strokeWidth
}//GEN-LAST:event_strokelargerMouseClicked

private void strokelargeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_strokelargeMouseClicked
// When the StrokeWidth icon is pressed:
    this.strokeWidth = 2.0f;
    sendShapeBoard(); //sends the whiteboard info with new strokeWidth
}//GEN-LAST:event_strokelargeMouseClicked

private void strokesmallMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_strokesmallMouseClicked
// When the StrokeWidth icon is pressed:
    this.strokeWidth = 1.0f;
    sendShapeBoard(); //When the StrokeWidth icon is pressed:
}//GEN-LAST:event_strokesmallMouseClicked

private void toolBarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toolBarMouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_toolBarMouseClicked

private void strokelargestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_strokelargestActionPerformed
// When the StrokeWidth icon is pressed:
    this.strokeWidth = 4.0f;
    sendShapeBoard(); //When the StrokeWidth icon is pressed:
}//GEN-LAST:event_strokelargestActionPerformed

private void rectangleMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rectangleMousePressed
// when the rectangle icon is pressed:
    this.paintArea1.saveCurrentInstance(); //saves the shapelist if not empty in a file
    shapeType = "Rectangle";
    this.paintArea1.setselector(false);
    sendShapeBoard();
    strokeEnabled = true;
    setEnableStroke();
    setselector("Rectangle");
}//GEN-LAST:event_rectangleMousePressed

private void paintArea1MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_paintArea1MouseMoved
// When the mouse is moved in the paintarea:
    int mousex = evt.getX(); //get the x-coordinate
    int mousey = evt.getY(); //get the y-coordinate
    mousexy.setText("x:   " + String.valueOf(mousex) + "    " + "y: " + String.valueOf(mousey)); //display in the status bar
}//GEN-LAST:event_paintArea1MouseMoved

private void paintArea1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_paintArea1MouseExited
// When the mouse exit from the whiteboard:
    mousexy.setText("mouse out of the whitearea");
}//GEN-LAST:event_paintArea1MouseExited

private void paintArea1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_paintArea1MouseEntered
// when the mouse enters in the whitearea:
    mousexy.setText("mouse just entered in the whitearea");
}//GEN-LAST:event_paintArea1MouseEntered

private void lineMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lineMouseClicked
// When the line icon is clicked:
    this.paintArea1.saveCurrentInstance();
    shapeType = "Line";
    strokeWidth = 1.0f;
    sendShapeBoard();
    strokeEnabled = true;
    setEnableStroke();
    setselector("Line");
}//GEN-LAST:event_lineMouseClicked

private void circleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_circleMouseClicked
// When the freehand icon is clicked:
    this.paintArea1.saveCurrentInstance();
    this.paintArea1.setselector(false);
    shapeType = "Freehand";
    this.paintArea1.setselector(false);
    strokeWidth = 1.0f;
    sendShapeBoard();
    strokeEnabled = true; //this will set the stroke enabled
    setEnableStroke();
    setselector("Freehand");
}//GEN-LAST:event_circleMouseClicked

    /**
     *sends the primary information about the shape to the paintarea
     **/
    private void sendShapeBoard() {
        shapeInfo shapeInfoPassed = new shapeInfo(); //create an instance of shapeinfo
        shapeInfoPassed.setShapeType(shapeType); //sets the shapetype in the shapeinfo like rectangle,circle which is passed by the function that users this functionetc
        shapeInfoPassed.setColor(color); //sets the color in the new shapeinfo
        shapeInfoPassed.setStrokeWidth(this.strokeWidth); //sets the strokewidth in the shapeinfo
        paintArea1.setShapeInfo(shapeInfoPassed); //sends the newly created shapeinfo to the paintarea that will be used as the recent object
    }

private void circleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_circleActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_circleActionPerformed

private void jnewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jnewActionPerformed
    paintArea1.clearBoard();
}//GEN-LAST:event_jnewActionPerformed

private void jTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextActionPerformed
    // TODO add your handling code here:
    fileChooser.resetChoosableFileFilters();
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Image (*.png)", "png"));
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Image (*.gif)", "gif"));
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Image (*.jpg)", "jpg", "jpeg"));
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Board file(*.out)", "out"));
    // the part of the above code is to select the type of files to be opened or closed
    int returnVal = fileChooser.showOpenDialog(this);
    while (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        if (file.exists()) {
            ObjectInputStream in;
            try {
                in = new ObjectInputStream(new FileInputStream(file.getPath()));
                Vector sh = (Vector) in.readObject();
                in.close();
                paintArea1.setShapes(sh);
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
            break;
        }
    }
}//GEN-LAST:event_jTextActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    save();  
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jExitActionPerformed
int chk=JOptionPane.showConfirmDialog(this, "save this" , "exit", 1);
    if (chk==0){ 
      save();
        if(connToServer){
            this.paintArea1.cleanUp();
            this.setVisible(false);
            this.dispose();
        }        
        else{
            this.setVisible(false);
            this.dispose();
        }
    }
    else if (chk==1) {
    if(connToServer) {
            this.paintArea1.cleanUp();
            this.setVisible(false);
            this.dispose();
    }        
        else{
            this.setVisible(false);
            this.dispose();
        }
    }

    else {}
}//GEN-LAST:event_jExitActionPerformed

private void jHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jHelpActionPerformed
    WhiteBoardHelp helpFrame = new WhiteBoardHelp();
        helpFrame.setVisible(true);
}//GEN-LAST:event_jHelpActionPerformed

private void jAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAboutActionPerformed
    JOptionPane.showMessageDialog(this, "eWhiteBoard.\nDeveloper: \n Prabesh Shrestha ", "About Us", JOptionPane.INFORMATION_MESSAGE);
    JOptionPane.showInternalConfirmDialog(this, flag); 
}//GEN-LAST:event_jAboutActionPerformed

    /**
     * sets the string in the status bar
     * @param t string that is passed to be displayed in the status bar
     * */
    private void setselector(String t) {
        selected.setText("Selected: " + t);
    }

    public void setStatus(String stat) {
       // status.setText("Selected: " + status);
        status.setText(stat);
    }
    
    /**
     * This function is called to enable the initially disabled stroke buttons or disable it
     * the calling function either passed true of false
     **/
    private void setEnableStroke() {
        this.strokesmall.setEnabled(strokeEnabled);
        this.strokelarge.setEnabled(strokeEnabled);
        this.strokelarger.setEnabled(strokeEnabled);
        this.strokelargest.setEnabled(strokeEnabled);
    }

    /**   This is the main function
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                mainGUI maingui = new mainGUI();
                maingui.setVisible(true); //makes the main frame visible
                //replaces the java cup by the image specified
                Toolkit.getDefaultToolkit().beep();
                Image myImg = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/whiteboard.png"));
                maingui.setIconImage(myImg);
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    //this.setUndecorated(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ConnectForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(ConnectForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(ConnectForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(ConnectForm.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu File;
    private javax.swing.JPanel buttonBar;
    private javax.swing.JButton circle;
    private javax.swing.JButton colorpallette;
    private javax.swing.JMenuItem connect;
    private javax.swing.JPanel connectDisconnect;
    private javax.swing.JPanel drawingArea;
    private javax.swing.JMenu edit;
    private javax.swing.JButton eraser;
    private javax.swing.JButton filledrectangle;
    private javax.swing.JMenu help;
    private javax.swing.JMenuItem jAbout;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JMenuItem jExit;
    private javax.swing.JMenuItem jHelp;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenuItem jText;
    private javax.swing.JMenuItem jnew;
    private javax.swing.JButton line;
    private javax.swing.JLabel mousexy;
    private javax.swing.JMenu network;
    private javax.swing.JMenuItem newnode;
    private javax.swing.JMenuItem newsuperpeer;
    private whiteBoard.paintArea paintArea1;
    private javax.swing.JButton rectangle;
    private javax.swing.JLabel selected;
    private javax.swing.JButton selectedcolor;
    private javax.swing.JLabel status;
    private javax.swing.JPanel statusANDmousexy;
    private javax.swing.JButton strokelarge;
    private javax.swing.JButton strokelarger;
    private javax.swing.JButton strokelargest;
    private javax.swing.JButton strokesmall;
    private javax.swing.JButton text;
    private javax.swing.JPanel toolBar;
    // End of variables declaration//GEN-END:variables
}